// Created by WXX on 2022/1/26 22:38
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

class DetectSquares {
public:
    unordered_map<int, unordered_map<int, int>> hash;

    DetectSquares() {

    }

    void add(vector<int> point) {
        int x = point[0], y = point[1];
        hash[y][x]++;
    }

    int count(vector<int> point) {

        int x = point[0], y = point[1];
        if (!hash.count(y)) return 0;

        int res = 0;
        auto cnt = hash[y];
        for (auto &[k, v] : hash) {
            if (k == y) continue;
            int d = k - y;
            // (x, k), (x + d, y), (x + d, k)
            res += (v.count(x) ? v[x] : 0) * (cnt.count(x + d) ? cnt[x + d] : 0) * (v.count(x + d) ? v[x + d] : 0);
            // (x, k), (x - d, y), (x - d, k)
            res += (v.count(x) ? v[x] : 0) * (cnt.count(x - d) ? cnt[x - d] : 0) * (v.count(x - d) ? v[x - d] : 0);
        }
        return res;
    }
};

int main() {

    DetectSquares *t = new DetectSquares();
    t->add({3, 10});
    t->add({11, 2});
    t->add({3, 2});
    cout << t->count({11, 10}) << endl;
    cout << t->count({14, 8}) << endl;
    t->add({11, 2});
    cout << t->count({11, 10}) << endl;

    return 0;
}
